import librosa  # 填充，默认频率为22050，可以改变频率
from scipy.io import wavfile  # 原音无损
import numpy as np            
import librosa.display
import matplotlib.pyplot as plt

# voice_path='voice_data2/train/left/zsn-left6.wav'
# voice_path='voice_data2/train/left/cxz_left_00.wav'
# voice_path=r'D:\_const\large_data\audio\_many_files\direction_data_1st\test\lefts\cxz_left_0 (1).wav'
voice_path='/home/asuspei/large_data/audio/_many_files/direction_data_1st/test/lefts/cxz_left_0 (1).wav'

fs, data = wavfile.read(voice_path)  # 原始频率，原始数据
print("长度 = {0} 秒".format(len(data) / fs))#长度/频率  得到时长
print(type(data))
plt.figure(figsize=(14, 5))
plt.plot(data)
plt.show()

y, sample_rate = librosa.load(voice_path)#用途：读取文件，可以是wav、mp3等格式。 #返回值  y : 音频的信号值，类型是ndarray  sr : 采样率
print("长度 = {0} 秒".format(len(y) / sample_rate))
print(type(y))

plt.figure(figsize=(14, 5))
# librosa.display.waveplot(y, sr=sample_rate)  # 绘制音频数组  # lower version
librosa.display.waveshow(y, sr=sample_rate)  # 绘制音频数组  # higher version
# plt.plot(y)
plt.show()
